package com.ydx.demo.controller;

import com.ydx.demo.CommonEntity.ResponseData;
import com.ydx.demo.entity.Medicine;
import com.ydx.demo.entity.Order;
import com.ydx.demo.entity.Shopcart;
import com.ydx.demo.mapper.OrderMapper;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RestController
@CrossOrigin(origins = "*") //   允许所有域名访问
public class OrderController {

    @Resource
    OrderMapper orderMapper;

    //查询订单表所有订单
    @GetMapping("/selorders")
    public ResponseData getOrders(){
        List<Order> data = orderMapper.finOrdersAll();
        return new ResponseData("200",null,true, data);
    }

    // 结算到订单页面
    @PostMapping("/insertOrders")
    public ResponseData insetOrders(@RequestBody Order order){
        orderMapper.insertOrders(order);
        return new ResponseData("200",null,true,"结算成功");
    }

    //修改订单表的状态
    @PostMapping("/updateState")
    public ResponseData updateImage(@RequestBody Order order){
        orderMapper.UpdateState(order);
        return new ResponseData("200",null,true, "修改订单状态成功");
    }
}
